<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>平时考核-被评人员</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="static/css/font.css">
<link rel="stylesheet" href="static/css/xadmin.css">
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/lib/layui/layui.js"></script>
<script type="text/javascript" src="static/js/xadmin.js"></script>
<style type="text/css">
.laytable-cell-1-eAccount{
	width:200px;
}


</style>
</head>

<body class="layui-anim layui-anim-up">

	<div class="x-nav">
		<span class="layui-breadcrumb"> <a>首页</a> <a>被评人员</a> <a> <cite>人员列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"> <i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body" id="container">
		<div class="layui-row">
			<div class="demoTable layui-col-md10 layui-form">

				员工工号：
				<div class="layui-inline">
					<input class="layui-input" name="account" id="eAccount"
						autocomplete="off">
				</div>
				&nbsp&nbsp&nbsp 员工姓名：
				<div class="layui-inline">
					<input class="layui-input" name="name" id="eName"
						autocomplete="off">
				</div>
				&nbsp&nbsp&nbsp 部门：

				<div class="layui-input-inline" style="width: 157px;">
					<select name="dep" id="dId" lay-filter="">
						<option value=""></option>
					</select>
				</div>
				<!--</div>-->
				&nbsp&nbsp&nbsp
				<button class="layui-btn" data-type="reload">搜索</button>
				<button class="layui-btn" style="padding: 2px 10px 4px 10px"
					onclick="toAdd()">
					<i class="layui-icon"></i>添加
				</button>
				<button class="layui-btn layui-btn-danger"
					data-type="getCheckLength" style="padding: 2px 10px 4px 10px">批量删除</button>
				<button class="layui-btn layui-btn-danger"
					data-type="getDatasubmmit" style="padding: 2px 10px 4px 10px">批量提交</button>

			</div>


		</div>
		<!--demoTable-->
	</div>
	<div style="text-align: center">
	<form class="layui-form" action="">
		<table class="layui-table"
			lay-data="{height: 'full-150', cellMinWidth:80, url:'pjEmployee/findSelective.do', page:true, id:'idTest'}"
			lay-filter="demo">
			<thead>
				<tr>
					
		            <th lay-data="{minWidth:100,align: 'center','background-color':'#bdccea'}" colspan="5">基本信息</th>
		            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">德</th>
		            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">能</th>
		            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">勤</th>
		            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">绩</th>
		            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">廉</th>
		        </tr>
				<tr>
					<th lay-data="{type:'checkbox', fixed: 'left'}"></th> 
					<!--
					<th
						lay-data="{field:'eAccount',templet: '<span>{{d.employee.eAccount}}</span>', width:100, fixed: true,align: 'center'}">
						工号</th>
						-->
					
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:100,align: 'center'}">
						部门</th>
					<th
						lay-data="{field:'eName', templet: '<span>{{d.employee.eName}}</span>',width:100,align: 'center'}">
						姓名</th>
					<th
						lay-data="{field:'ePhone', templet: '<span>{{d.employee.ePhone}}</span>',minWidth:150,align: 'center'}">
						电话</th>
					<th
						lay-data="{field:'eAccount', templet: '<span>{{d.employee.eAccount}}</span>',minWidth:100,align: 'center'}">
						工号</th>
					<th
						lay-data="{field:'pjzb0',width:100,align: 'center',edit:'text',id:'pjzb0'}">评价指标0
					</th>
					<th
						lay-data="{field:'pjzb1',width:100,align: 'center',edit:'text',id:'pjzb1'}">评价指标1
					</th>
					<th
						lay-data="{field:'pjzb2',width:100,align: 'center',edit:'text',id:'pjzb2'}">评价指标2
					</th>
					<th
						lay-data="{field:'eUrgentPerson', templet: '做成选择框进行选择',width:150 ,align: 'center'}">
						评价指标4</th>
					<th
						lay-data="{field:'eUrgentPerson', templet: '<span>{{d.employee.eUrgentPerson}}</span>',width:100 ,align: 'center'}">
						评价指标5</th>
					<th
						lay-data="{field:'pName', templet: '<span>{{d.position.pName}}</span>',minWidth:100,align: 'center'}">
						评价指标6</th>
					<th
						lay-data="{field:'eBasePay', templet: '<span>{{d.employee.eBasePay}}</span>',width:100,align: 'center'}">
						评价指标7</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:100,align: 'center'}">
						评价指标8</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标9</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标10</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标11</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标12</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标13</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标14</th>
					<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
						评价指标15</th>
						<!-- 
					<th
						lay-data="{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}"></th>
						 -->
				</tr>
			</thead>
		</table>
		</form>
	</div>

	</div>
	<!-- 
	<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
 -->
	<script>

    window.onload = function () {
        //加载部门下拉搜索框
        var dId = $("#dId");
        $.ajax({
            url: 'department/findSelective.do?page=1&limit=999', //分页限制为999条，就是全部
            dataType: 'json',
            type: 'post',
            success: function (result) {
                // console.log(result.data);
                $.each(result.data, function (index, item) {
                    // console.log(index + "&" + item.dId);
                    dId.append("<option value=" + item.dId + ">" + item.dName + "</option>");// 下拉菜单里添加元素
                })
                layui.form.render('select');  //渲染select

            }
        });

    }

    // add按钮的跳转函数
    function toAdd() {
        layer.open({
            type: 2,
            area: ['98%', '80%'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            title: '添加',
            content: 'toPage.do?url=admin/employee/employee-add.html'
        });
    }

    // 刷新(主要用于批量删除，不能直接在里面刷新，那样会使操作失败，要跳出来执行)
    function myReload() {
        location.replace(location.href);
    }

    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        // form.render('select');

        //监听表格复选框选择
        // table.on('checkbox(demo)', function(obj){
        //     console.log(obj)
        // });

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            alert("单独处理");
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定要删除吗111', function (index) {
                    $.ajax({
                        type: 'post',
                        url: 'pjEmployee/deleteByPrimaryKey.do',
                        data: {"id": data.employee.eId},
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('员工已删除!', {icon: 1, time: 4000});
                                obj.del();
                            }else{
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }

                    });
                    obj.del();
                    layer.close(index);
                    // location.reload();
                });
            } else if (obj.event === 'edit') {
              
                layer.open({
                    type: 2,
                    area: ['98%', '80%'],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: '编辑',
                    content: 'toPage.do?url=admin/employee/employee-edit.html?eId='
                        + data.employee.eId
                        + '&dId=' + data.department.dId
                        + '&pId=' + data.position.pId
                        + '&rbId=' + data.rankBonus.rbId
                });
            }
        });

        var $ = layui.$, active = {

            reload: function () {
                var eAccount = $('#eAccount');
                var eName = $('#eName');123
                var dId = $('#dId');
             
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        e_account: eAccount.val(),
                        e_name: eName.val(),
                        d_id: dId.val()
                    }
                });
            },
            getCheckLength: function () { //获取选中数目
            	alert("批量处理");
                var checkStatus = table.checkStatus('idTest')
                , data = checkStatus.data;
                
                var pjzb0s = table.checkStatus('pjzb0')
                , data1 = pjzb0s.data;
            	alert("批量处理111=="+pjzb0s);
            	alert("批量处理222=="+data1);
                
           		if(data.length<=0){
           		layer.msg("请至少选择一条数据进行操作")
           			return;
           		}
           		
           		//在下面把标哥数据提取出来，直接提交后台即可
                var ids = [];
                $.each(data, function (index, item) {
                    ids.push(item.employee.eId);
                });
                
              //在下面把标哥数据提取出来，直接提交后台即可
                var ids1 = [];
                $.each(data1, function (index, item) {
                    ids1.push(item.pjzb0);
                });
                console.log(ids);
                layer.confirm('确定要删除吗', function (index) {

                    $.ajax({
                        type: 'post',
                        url: 'pjEmployee/deleteByQuery.do',
                        data: {"arr": ids,"arr1": ids1},
                        traditional: true,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                              
                            }
                            else {
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            alert("error" + data);
                            layer.alert("网路错误111", {icon: 5});
                        }
                    });
                    layer.close(index);
                    relo();

                });
            },
            getDatasubmmit: function () { //获取选中数目
            	alert("批量提交1");
            	layui.use(['form', 'table', 'laydate'], function(){
            		//获取标哥的所有数据，保存到数据库中
            		var datas1 = new Array();
            		var datas2 = new Array();
            		var datas3 = new Array();
            		var datas4 = new Array();
            		alert("批量提交2");
            		var datas = layui.table.cache["idTest"]
            		console.log(datas);
            		for(i=0;i<datas.length;i++){
            			datas1.push(datas[i].department);
            			datas2.push(datas[i].pjzb0);
            			datas3.push(datas[i].pjzb1);
            			datas4.push(datas[i].position);
            		}
            		
            		alert("批量提交3");
            		console.log(datas1);
            		console.log(datas2);
            		console.log(datas3);
            		console.log(datas4);123
            		
            		$.ajax({
                        type:'post',
                        url:'pjEmployee/EmpEvaDataSubmit.do',
                        traditional: true,//加上此项可以传数组
                        data: {
                            "datas1":datas1,
                            "datas2":datas2,
                            "datas3":datas3,
                            "datas4":datas4,
                            
                        },
                        dataType:'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('评价成功!', {icon: 1, time: 4000});
                              
                            }
                            else {
                                layer.msg('评价失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            alert("error" + data);
                            layer.alert("网路错误", {icon: 5});
                        }

                    });
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function relo() {
            var eAccount = $('#eAccount');
            var eName = $('#eName');
            var dId = $('#dId');
        
            // 执行重载
            table.reload('idTest', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    e_account: eAccount.val(),
                    e_name: eName.val(),
                    d_id: dId.val()
                }
            });
        }
    });

</script>

</body>

</html>
